* Clean up

clear all

set maxvar 10000

/*
* Set working directory: please set your own
cd "/Users/vicentevalentim/Desktop/fragmentation_replication_bjps"
*/

* Open dataset

use Data/Dinasetal2015_updated2018.dta, clear

* Generate country-year variable
tostring year, replace force
gen country_year = countryname + year
destring year, replace
ta country_year
replace country_year = "Moldova2009.2" if country_year == "Moldova2009.199951"
replace country_year = "Moldova2009.1" if country_year == "Moldova2009.099976"

* Homogenize variable names
rename seats absseat
rename votes pervote
sort country_year

gen date = .

replace date = 200607 if country_year == "Albania2005"
replace date = 200906 if country_year == "Albania2009"
replace date = 201306 if country_year == "Albania2013"
replace date = 201706 if country_year == "Albania2017"
replace date = 199706 if country_year == "Bolivia1_1997"
replace date = 200206 if country_year == "Bolivia2_2002"
replace date = 200512 if country_year == "Bolivia3_2005"
replace date = 200912 if country_year == "Bolivia4_2009"
replace date = 200604 if country_year == "Peru1_2006"
replace date = 201104 if country_year == "Peru2_2011"
replace date = 201604 if country_year == "Peru3_2016" 
replace date = 199307 if country_year == "Seychelles1993"
replace date = 199803 if country_year == "Seychelles1998"
replace date = 200212 if country_year == "Seychelles2002"
replace date = 200705 if country_year == "Seychelles2007"
replace date = 199212 if country_year == "Slovenia1_1992"
replace date = 199611 if country_year == "Slovenia2_1996"
replace date = 200010 if country_year == "Slovenia3_2000"
replace date = 200410 if country_year == "Slovenia4_2004"
replace date = 200809 if country_year == "Slovenia5_2008"
replace date = 201112 if country_year == "Slovenia6_2011"
replace date = 201407 if country_year == "Slovenia7_2014"
replace date = 201806 if country_year == "Slovenia8_2018"
replace date = 199212 if country_year == "Taiwan1_1992"
replace date = 199512 if country_year == "Taiwan2_1995"
replace date = 199812 if country_year == "Taiwan3_1998"
replace date = 200112 if country_year == "Taiwan4_2001"
replace date = 200412 if country_year == "Taiwan5_2004"
replace date = 200904 if country_year == "Moldova1_2009"
replace date = 201210 if country_year == "Ukraine1_2012"
replace date = 201410 if country_year == "Ukraine2_2014"
replace date = 201809 if country_year == "Sweden2018"
replace date = 201212 if country_year == "Romania2012"
replace date = 201612 if country_year == "Romania2016"
replace date = 201709 if country_year == "Norway2017"
replace date = 201709 if country_year == "New Zealand2017"
replace date = 201411 if country_year == "Moldova2014"
replace date = 201610 if country_year == "Lithuania2016"
replace date = 201810 if country_year == "Latvia2018"
replace date = 201704 if country_year == "Armenia2017"
replace date = 201506 if country_year == "Denmark2015"
replace date = 201204 if country_year == "South Korea2012"
replace date = 201609 if country_year == "Seychelles2016"
replace date = 198804 if country_year == "South Korea1988"
replace date = 200801 if country_year == "Taiwan6_2008"
replace date = 201201 if country_year == "Taiwan7_2012"
replace date = 201601 if country_year == "Taiwan8_2016"
replace date = 201803 if country_year == "Italy2018"
replace date = 201610 if country_year == "Iceland2016"
replace date = 201710 if country_year == "Iceland2017"
replace date = 201804 if country_year == "Hungary2018"
replace date = 201109 if country_year == "Seychelles2011"
replace date = 201109 if country_year == "Seychelles2011"
replace date = 201807 if country_year == "Mexico2018"
replace date = 199203 if country_year == "Albania1992"
replace date = 199706 if country_year == "Albania1997"
replace date = 200106 if country_year == "Albania2001"
replace date = 200507 if country_year == "Albania2005"
replace date = 200906 if country_year == "Albania2009"
replace date = 201306 if country_year == "Albania2013"
replace date = 201706 if country_year == "Albania2017"
replace date = 199507 if country_year == "Armenia1995"
replace date = 199905 if country_year == "Armenia1999"
replace date = 200305 if country_year == "Armenia2003"
replace date = 200705 if country_year == "Armenia2007"
replace date = 201205 if country_year == "Armenia2012"
replace date = 201704 if country_year == "Armenia2017"
replace date = 199910 if country_year == "Austria1999"
replace date = 200610 if country_year == "Austria2006"
replace date = 201309 if country_year == "Austria2013"
replace date = 201710 if country_year == "Austria2017"
replace date = 200206 if country_year == "Bolivia2002"
replace date = 200512 if country_year == "Bolivia2005"
replace date = 200912 if country_year == "Bolivia2009"
replace date = 199006 if country_year == "Bulgaria1990"
replace date = 199110 if country_year == "Bulgaria1991"
replace date = 199704 if country_year == "Bulgaria1997"
replace date = 200106 if country_year == "Bulgaria2001"
replace date = 200506 if country_year == "Bulgaria2005"
replace date = 200907 if country_year == "Bulgaria2009"
replace date = 201305 if country_year == "Bulgaria2013"
replace date = 201410 if country_year == "Bulgaria2014"
replace date = 201703 if country_year == "Bulgaria2017"
replace date = 199605 if country_year == "Cyprus1996"
replace date = 200605 if country_year == "Cyprus2006"
replace date = 201105 if country_year == "Cyprus2011"
replace date = 201605 if country_year == "Cyprus2016"
replace date = 200001 if country_year == "Croatia2000"
replace date = 201112 if country_year == "Croatia2011"
replace date = 201511 if country_year == "Croatia2015"
replace date = 201609 if country_year == "Croatia2016"
replace date = 199006 if country_year == "Czech Republic1990"
replace date = 199206 if country_year == "Czech Republic1992"
replace date = 200606 if country_year == "Czech Republic2006"
replace date = 201310 if country_year == "Czech Republic2013"
replace date = 201710 if country_year == "Czech Republic2017"
replace date = 198709 if country_year == "Denmark1987"
replace date = 198805 if country_year == "Denmark1988"
replace date = 199012 if country_year == "Denmark1990"
replace date = 200111 if country_year == "Denmark2001"
replace date = 200711 if country_year == "Denmark2007"
replace date = 201109 if country_year == "Denmark2011"
replace date = 201506 if country_year == "Denmark2015"
replace date = 199209 if country_year == "Estonia1992"
replace date = 199503 if country_year == "Estonia1995"
replace date = 200303 if country_year == "Estonia2003"
replace date = 200703 if country_year == "Estonia2007"
replace date = 201503 if country_year == "Estonia2015"
replace date = 200403 if country_year == "Georgia2004"
replace date = 200805 if country_year == "Georgia2008"
replace date = 196109 if country_year == "Germany1961"
replace date = 196509 if country_year == "Germany1965"
replace date = 196909 if country_year == "Germany1969"
replace date = 197211 if country_year == "Germany1972"
replace date = 197610 if country_year == "Germany1976"
replace date = 198010 if country_year == "Germany1980"
replace date = 198303 if country_year == "Germany1983"
replace date = 198701 if country_year == "Germany1987"
replace date = 199012 if country_year == "Germany1990"
replace date = 199410 if country_year == "Germany1994"
replace date = 199809 if country_year == "Germany1998"
replace date = 200209 if country_year == "Germany2002"
replace date = 200509 if country_year == "Germany2005"
replace date = 200909 if country_year == "Germany2009"
replace date = 201709 if country_year == "Germany2017"
replace date = 199310 if country_year == "Greece1993"
replace date = 200004 if country_year == "Greece2000"
replace date = 200403 if country_year == "Greece2004"
replace date = 200709 if country_year == "Greece2007"
replace date = 200910 if country_year == "Greece2009"
replace date = 201205 if country_year == "Greece2012.099976"
replace date = 201206 if country_year == "Greece2012.199951"
replace date = 201501 if country_year == "Greece2015.099976"
replace date = 201509 if country_year == "Greece2015.199951"  
replace date = 200604 if country_year == "Hungary2006"
replace date = 201004 if country_year == "Hungary2010"
replace date = 201404 if country_year == "Hungary2014"
replace date = 201804 if country_year == "Hungary2018"
replace date = 200305 if country_year == "Iceland2003"
replace date = 200705 if country_year == "Iceland2007"
replace date = 200904 if country_year == "Iceland2009"
replace date = 201304 if country_year == "Iceland2013"
replace date = 201610 if country_year == "Iceland2016"
replace date = 201710 if country_year == "Iceland2017"
replace date = 195507 if country_year == "Israel1955"
replace date = 195907 if country_year == "Israel1959"
replace date = 196108 if country_year == "Israel1961"
replace date = 197312 if country_year == "Israel1973"
replace date = 197705 if country_year == "Israel1977"
replace date = 198407 if country_year == "Israel1984"
replace date = 198811 if country_year == "Israel1988"
replace date = 199605 if country_year == "Israel1996"
replace date = 199905 if country_year == "Israel1999"
replace date = 200301 if country_year == "Israel2003"
replace date = 200603 if country_year == "Israel2006"
replace date = 200902 if country_year == "Israel2009"
replace date = 201301 if country_year == "Israel2013"
replace date = 201503 if country_year == "Israel2015"
replace date = 199403 if country_year == "Italy1994"
replace date = 200604 if country_year == "Italy2006"
replace date = 200804 if country_year == "Italy2008"
replace date = 201302 if country_year == "Italy2013"
replace date = 199810 if country_year == "Latvia1998"
replace date = 200610 if country_year == "Latvia2006"
replace date = 201010 if country_year == "Latvia2010"
replace date = 201109 if country_year == "Latvia2011"
replace date = 201410 if country_year == "Latvia2014"
replace date = 201810 if country_year == "Latvia2018"
replace date = 200010 if country_year == "Lithuania2000"
replace date = 200410 if country_year == "Lithuania2004"
replace date = 200810 if country_year == "Lithuania2008"
replace date = 201210 if country_year == "Lithuania2012"
replace date = 201610 if country_year == "Lithuania2016"
replace date = 199810 if country_year == "Macedonia1998"
replace date = 200007 if country_year == "Mexico2000"
replace date = 200306 if country_year == "Mexico2003"
replace date = 201506 if country_year == "Mexico2015"
replace date = 199402 if country_year == "Moldova1994"
replace date = 199803 if country_year == "Moldova1998"
replace date = 200102 if country_year == "Moldova2001"
replace date = 200503 if country_year == "Moldova2005"
replace date = 200904 if country_year == "Moldova2009.099976"
replace date = 200907 if country_year == "Moldova2009.199951"
replace date = 201011 if country_year == "Moldova2010"
replace date = 201411 if country_year == "Moldova2014"
replace date = 200903 if country_year == "Montenegro2009"
replace date = 201210 if country_year == "Montenegro2012"
replace date = 201610 if country_year == "Montenegro2012"
replace date = 194605 if country_year == "Netherlands1946"
replace date = 194807 if country_year == "Netherlands1948"
replace date = 195206 if country_year == "Netherlands1952"
replace date = 195606 if country_year == "Netherlands1956"
replace date = 195903 if country_year == "Netherlands1959"
replace date = 196305 if country_year == "Netherlands1963"
replace date = 196702 if country_year == "Netherlands1967"
replace date = 197104 if country_year == "Netherlands1971"
replace date = 197211 if country_year == "Netherlands1972"
replace date = 197705 if country_year == "Netherlands1977"
replace date = 198105 if country_year == "Netherlands1981"
replace date = 198209 if country_year == "Netherlands1982"
replace date = 198605 if country_year == "Netherlands1986"
replace date = 198909 if country_year == "Netherlands1989"
replace date = 199405 if country_year == "Netherlands1994"
replace date = 199805 if country_year == "Netherlands1998"
replace date = 200205 if country_year == "Netherlands2002"
replace date = 200611 if country_year == "Netherlands2006"
replace date = 201006 if country_year == "Netherlands2010"
replace date = 201209 if country_year == "Netherlands2012"
replace date = 201703 if country_year == "Netherlands2017"
replace date = 199610 if country_year == "New Zealand1996"
replace date = 199911 if country_year == "New Zealand1999"
replace date = 200207 if country_year == "New Zealand2002"
replace date = 200509 if country_year == "New Zealand2005"
replace date = 200811 if country_year == "New Zealand2008"
replace date = 201111 if country_year == "New Zealand2011"
replace date = 201409 if country_year == "New Zealand2014"
replace date = 201709 if country_year == "New Zealand2017"
replace date = 199309 if country_year == "Norway1993"
replace date = 199709 if country_year == "Norway1997"
replace date = 200109 if country_year == "Norway2001"
replace date = 200509 if country_year == "Norway2005"
replace date = 200909 if country_year == "Norway2009"
replace date = 201309 if country_year == "Norway2013"
replace date = 201709 if country_year == "Norway2017"
replace date = 200604 if country_year == "Peru2006"
replace date = 201104 if country_year == "Peru2011"
replace date = 201604 if country_year == "Peru2016"
replace date = 199309 if country_year == "Poland1993"
replace date = 200109 if country_year == "Poland2001"
replace date = 200509 if country_year == "Poland2005"
replace date = 200710 if country_year == "Poland2007"
replace date = 201110 if country_year == "Poland2011"
replace date = 199611 if country_year == "Romania1996"
replace date = 200011 if country_year == "Romania2000"
replace date = 200411 if country_year == "Romania2004"
replace date = 200811 if country_year == "Romania2008"
replace date = 201212 if country_year == "Romania2012"
replace date = 201612 if country_year == "Romania2016"
replace date = 199512 if country_year == "Russia1995"
replace date = 200312 if country_year == "Russia2003"
replace date = 200712 if country_year == "Russia2007"
replace date = 200212 if country_year == "Seychelles2002"
replace date = 200705 if country_year == "Seychelles2007"
replace date = 199006 if country_year == "Slovakia1990"
replace date = 199206 if country_year == "Slovakia1992"
replace date = 199409 if country_year == "Slovakia1994"
replace date = 199809 if country_year == "Slovakia1998"
replace date = 200606 if country_year == "Slovakia2006"
replace date = 201203 if country_year == "Slovakia2012"
replace date = 201603 if country_year == "Slovakia2016"
replace date = 197009 if country_year == "Sweden1970"
replace date = 197309 if country_year == "Sweden1973"
replace date = 197609 if country_year == "Sweden1976"
replace date = 197909 if country_year == "Sweden1979"
replace date = 198209 if country_year == "Sweden1982"
replace date = 198809 if country_year == "Sweden1988"
replace date = 199409 if country_year == "Sweden1994"
replace date = 199809 if country_year == "Sweden1998"
replace date = 200209 if country_year == "Sweden2002"
replace date = 200609 if country_year == "Sweden2006"
replace date = 201409 if country_year == "Sweden2014"
replace date = 201809 if country_year == "Sweden2018"
replace date = 199512 if country_year == "Turkey1995"
replace date = 200211 if country_year == "Turkey2002"
replace date = 199803 if country_year == "Ukraine1998"
replace date = 200203 if country_year == "Ukraine2002"
replace date = 200603 if country_year == "Ukraine2006"
replace date = 201210 if country_year == "Ukraine2012"
replace date = 201410 if country_year == "Ukraine2014"
replace date = 199512 if country_year == "Taiwan1995"
replace date = 199812 if country_year == "Taiwan1998"
replace date = 200112 if country_year == "Taiwan2001"
replace date = 200412 if country_year == "Taiwan2004"
replace date = 200801 if country_year == "Taiwan2008"
replace date = 201201 if country_year == "Taiwan2012"
replace date = 201601 if country_year == "Taiwan2016"
replace date = 199605 if country_year == "Albania1996"
replace date = 199410 if country_year == "Austria1994"
replace date = 200211 if country_year == "Austria2002"
replace date = 200809 if country_year == "Austria2008"
replace date = 199706 if country_year == "Bolivia1997"
replace date = 199412 if country_year == "Bulgaria1994"
replace date = 199208 if country_year == "Croatia1992"
replace date = 199510 if country_year == "Croatia1995"
replace date = 199605 if country_year == "Czech Republic1996"
replace date = 199806 if country_year == "Czech Republic1998"
replace date = 200206 if country_year == "Czech Republic2002"
replace date = 201005 if country_year == "Czech Republic2010"
replace date = 197109 if country_year == "Denmark1971"
replace date = 197312 if country_year == "Denmark1973"
replace date = 197501 if country_year == "Denmark1975"
replace date = 197910 if country_year == "Denmark1979"
replace date = 198112 if country_year == "Denmark1981"
replace date = 198401 if country_year == "Denmark1984"
replace date = 199409 if country_year == "Denmark1994"
replace date = 200502 if country_year == "Denmark2005"
replace date = 199903 if country_year == "Estonia1999"
replace date = 201103 if country_year == "Estonia2011"
replace date = 201210 if country_year == "Georgia2012"
replace date = 201610 if country_year == "Georgia2016"
replace date = 194908 if country_year == "Germany1949"
replace date = 195309 if country_year == "Germany1953"
replace date = 195709 if country_year == "Germany1957"
replace date = 199609 if country_year == "Greece1996"
replace date = 199003 if country_year == "Hungary1990"
replace date = 199405 if country_year == "Hungary1994"
replace date = 199805 if country_year == "Hungary1998"
replace date = 200204 if country_year == "Hungary2002"
replace date = 198106 if country_year == "Israel1981"
replace date = 199206 if country_year == "Israel1992"
replace date = 199604 if country_year == "Italy1996"
replace date = 200105 if country_year == "Italy2001"
replace date = 201803 if country_year == "Italy2018"
replace date = 199306 if country_year == "Latvia1993"
replace date = 199509 if country_year == "Latvia1995"
replace date = 199509 if country_year == "Latvia1995"
replace date = 199210 if country_year == "Lithuania1992"
replace date = 199610 if country_year == "Lithuania1996"
replace date = 200209 if country_year == "Macedonia2002"
replace date = 200607 if country_year == "Macedonia2006"
replace date = 200806 if country_year == "Macedonia2008"
replace date = 201106 if country_year == "Macedonia2011"
replace date = 200907 if country_year == "Mexico2009"
replace date = 200301 if country_year == "Netherlands2003"
replace date = 198909 if country_year == "Norway1989"
replace date = 199709 if country_year == "Poland1997"
replace date = 199209 if country_year == "Romania1992"
replace date = 199312 if country_year == "Russia1993"
replace date = 199912 if country_year == "Russia1999"
replace date = 201609 if country_year == "Seychelles2016"
replace date = 200209 if country_year == "Slovakia2002"
replace date = 201006 if country_year == "Slovakia2010"
replace date = 199212 if country_year == "Slovenia1992"
replace date = 199611 if country_year == "Slovenia1996"
replace date = 200010 if country_year == "Slovenia2000"
replace date = 200410 if country_year == "Slovenia2004"
replace date = 200809 if country_year == "Slovenia2008"
replace date = 201112 if country_year == "Slovenia2011"
replace date = 201407 if country_year == "Slovenia2014"
replace date = 201806 if country_year == "Slovenia2018"
replace date = 198804 if country_year == "South Korea1988"
replace date = 199203 if country_year == "South Korea1992"
replace date = 199604 if country_year == "South Korea1996"
replace date = 200004 if country_year == "South Korea2000"
replace date = 200404 if country_year == "South Korea2004"
replace date = 200804 if country_year == "South Korea2008"
replace date = 198509 if country_year == "Sweden1985"
replace date = 199109 if country_year == "Sweden1991"
replace date = 198711 if country_year == "Turkey1987"
replace date = 199904 if country_year == "Turkey1999"
replace date = 200707 if country_year == "Turkey2007"
replace date = 201106 if country_year == "Turkey2011"
replace date = 200709 if country_year == "Ukraine2007"
replace date = 200210 if country_year == "Latvia2002"
replace date = 200311 if country_year == "Croatia2003"
replace date = 200711 if country_year == "Croatia2007"
replace date = 201309 if country_year == "Germany2013"
replace date = 194901 if country_year == "Israel1949"
replace date = 195107 if country_year == "Israel1951"
replace date = 195507 if country_year == "Israel1955"
replace date = 195907 if country_year == "Israel1959"
replace date = 196108 if country_year == "Israel1961"
replace date = 196511 if country_year == "Israel1965"
replace date = 196910 if country_year == "Israel1969"
replace date = 197312 if country_year == "Israel1973"
replace date = 197705 if country_year == "Israel1977"
replace date = 198106 if country_year == "Israel1981"
replace date = 198407 if country_year == "Israel1984"
replace date = 198811 if country_year == "Israel1988"
replace date = 199206 if country_year == "Israel1992"
replace date = 199605 if country_year == "Israel1996"
replace date = 200301 if country_year == "Israel2003"
replace date = 200603 if country_year == "Israel2006"
replace date = 200902 if country_year == "Israel2009"
replace date = 199204 if country_year == "Italy1992"
replace date = 199110 if country_year == "Turkey1991"
replace date = 200507 if country_year == "Albania2005"
replace date = 200805 if country_year == "Georgia2008"
replace date = 199512 if country_year == "Austria1995"
replace date = 197702 if country_year == "Denmark1977"
replace date = 199803 if country_year == "Denmark1998"
replace date = 200609 if country_year == "Montenegro2006"
replace date = 201610 if country_year == "Montenegro2016"
replace date = 201112 if country_year == "Russia2011"
replace date = 201204 if country_year == "South Korea2012"
replace date = 201604 if country_year == "South Korea2016"
replace date = 201009 if country_year == "Sweden2010"
replace date = 199212 if country_year == "Taiwan1992"
replace date = 201511 if country_year == "Turkey2015"
replace date = 200105 if country_year == "Cyprus2001"
replace date = 200607 if country_year == "Mexico2006"
replace date = 201207 if country_year == "Mexico2012"
replace date = 198311 if country_year == "Turkey1983"
replace date = 200904 if country_year == "Moldova2009.1"
replace date = 200907 if country_year == "Moldova2009.2"
replace date = 201210 if countryname == "Montenegro" & year == 2012
replace date = 201610 if countryname == "Montenegro" & year == 2016
replace date = 201506 if countryname == "Turkey" & year == 2015 & edate == "07jun2015"
replace date = 201511 if countryname == "Turkey" & year == 2015 & edate == "01nov2015"
replace date = 201609 if countryname == "Croatia" & year == 2016
replace date = 201511 if countryname == "Croatia" & year == 2015
replace date = 200507 if countryname == "Albania" & year == 2005
replace date = 200906 if countryname == "Albania" & year == 2009
replace date = 201306 if countryname == "Albania" & year == 2013
replace date = 201706 if countryname == "Albania" & year == 2017
replace date = 199512 if countryname == "Austria" & year == 1995
replace date = 201609 if countryname == "Seychelles" & year == 2016
replace date = 200609 if countryname == "Montenegro" & year == 2006
replace date = 201112 if countryname == "Russia" & year == 2011
replace date = 201009 if countryname == "Sweden" & year == 2010
replace date = 200801 if countryname == "Taiwan" & year == 2008
replace date = 201011 if countryname == "Taiwan" & year == 2010
replace date = 201601 if countryname == "Taiwan" & year == 2016
replace date = 197702 if countryname == "Denmark" & year == 1977
replace date = 199803 if countryname == "Denmark" & year == 1998
replace date = 201604 if countryname == "South Korea" & year == 2016

ta country_year if threshold == .

* Generate country-date variable
tostring date, replace
gen cntrydate = countryname + date
destring date, replace
ta cntrydate

* Fix Albania 2009, which has a threshold of 3, but missing in the data
replace threshold = 3 if country_year == "Albania2009"

* Drop missing observations that should not be there
*br if date == .
drop if date == .

* Drop elections without a threshold (Macedonia besides 1998)
ta threshold, mis
ta cntrydate if threshold == .
drop if threshold == .

* Drop Slovenia before 2000, because it had no threshold
drop if cntrydate  == "Slovenia199212"
drop if cntrydate  == "Slovenia199611"

encode countryname, gen(country_code)

ta country_code, nolabel

forvalues x = 1/38{
ta cntrydate threshold if country_code == `x'
}

* Fix treat variable
drop treat
gen treat = .
replace treat = 0 if absseat == 0
replace treat = 1 if absseat > 0

* Homogenize threshold in Cyprus
replace threshold = 1.79 if countryname == "Cyprus"

** Further manipulations

destring date, replace

* Check how many parties in and out of parliament we have
forvalues x = 1/38{
ta cntrydate treat if country_code == `x'
}

* Generate variable performance, indicating whether a party is above the threshold
gen performance = pervote - threshold
sum performance

* Fixing country variable
drop country
encode countryname, gen(country)

* Check it's gone well
forvalues x = 1/38{
ta countryname if country == `x'
}

* Correct thresholds
replace threshold = 0.67 if cntrydate == "Netherlands195606"
replace threshold = 5 if cntrydate == "Lithuania200010"
replace threshold = 4 if cntrydate == "Moldova201011"

* Generate variable indicating the seatshare of each party
bysort country date: egen totseats = sum(absseat)
gen seatshare = absseat / totseats
ta absseat if seatshare == .
replace seatshare = 0 if absseat == 0
ta absseat if seatshare > 0

ta country if cntrydate == "Croatia201511"
forvalues x = 1/34{
ta cntrydate treat if country == `x'
}

* Drop parties that got 0% of the vote and won no seats
drop if pervote == 0 & absseat == 0

forvalues x = 1/38{
ta cntrydate threshold  if country == `x'
}

ta country, nolabel
forvalues x = 1/38{
ta cntrydate treat  if country == `x'
}

saveold Data/fragmentation_partylevel_dinasonly.dta, replace version(12)


